473,416 Members | 1,559 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

How to make a menu


Hi friends, I want to make menu in my C program

For example:

Main Menu: (1) Enter Data, (2) Control Variables (3) Exit

I want to make this menu to go through the options just pressing numbers
1,2 and 3.

Thanks Daniel
--
Posted via http://dbforums.com
Nov 13 '05 #1
3 34200
dapernia wrote:
Hi friends, I want to make menu in my C program

For example:

Main Menu: (1) Enter Data, (2) Control Variables (3) Exit

I want to make this menu to go through the options just pressing numbers
1,2 and 3.

Thanks Daniel
--
Posted via http://dbforums.com


One method for menus is to use tables.
typedef void (*Ptr_To_Function)(void);
struct Menu_Record
{
unsigned int option_number;
const char * text;
Ptr_To_Function process_function;
};

void Enter_Data(void);
void Control_Variables(void);

struct Menu_Record main_menu[] =
{
{1, "Enter Data", Enter_Data},
{2, "Control Variables {before the get out of control}",
Control_Variables},
{3, "Exit", NULL}
};
const unsigned int NUM_MAIN_OPTIONS =
sizeof (main_menu) / sizeof(main_menu[0]);

int main(void)
{
unsigned int i;
printf("Main Menu:\n");
for (i = 0; i < NUM_MAIN_OPTIONS; ++i)
{
printf("\t(%d) %s\n",
main_menu[i].option_number,
main_menu[i].text);
}
/* enter the selection ... */
/* now process the selection */
for (i = 0; i < NUM_MAIN_OPTIONS; ++i)
{
if (selection == main_menu[i].option_number)
{
if (main_menu[i].process_function)
main_menu[i].process_function();
break;
}
}
return EXIT_SUCCESS;
}
This menu handling method allows you to have many menus
but only require one driver to process the tables. The
number of options can shrink or expand without having
to change the execution code (driver). This method can
be expanded to handle sub-menus too.

It is a nice feeling to spend less than 10 minutes to
update a menu by adding in a new row, rather than having
to locate a switch (or if-else ladder), modify it and
retest (which could take hours or days).

--
Thomas Matthews
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html

Nov 13 '05 #2
"dapernia" <me*********@dbforums.com> wrote in message
news:32****************@dbforums.com...

Hi friends, I want to make menu in my C program

For example:

Main Menu: (1) Enter Data, (2) Control Variables (3) Exit

I want to make this menu to go through the options just pressing numbers
1,2 and 3.

Thanks Daniel
--
Posted via http://dbforums.com

I just answered that under a question asking what conio.h was. If you use
MSDOS, the standard compilers (Borland, Microsoft,etc) add functions to
query if a key is waiting, read the keyboard, push back a key to the
keyboard buffer, directly write to console (much faster than printf()), etc.

--
ArWeGod@sbc_global.net
Remove underscore to email.
Nov 13 '05 #3
dapernia wrote:

For example:

Main Menu: (1) Enter Data, (2) Control Variables (3) Exit

I want to make this menu to go through the options just pressing
numbers 1,2 and 3.


Without using ENTER or CR or whatever your terminal provides, not
possible under pure ISO C. However, just to add to the confusion,
you can use a terminal with programmable function keys, and
program 3 of them to generate the sequences "0\n", "1\n", "2\n".
This gives the operator the effect desired.

--
Chuck F (cb********@yahoo.com) (cb********@worldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!
Nov 13 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Gernot Frisch | last post by:
Hi, I have found some menu functions. It works quite well, but how can I replace it with a simple <a href> if javascript is turned off? I reduced my code to:...
3
by: Heather | last post by:
I notice the Tag property for menu items. Is there a way to assign say a 1 to the Tag property of certain menu items and then make those menu items not visible programatically? Thanks! Heather
0
by: keith | last post by:
I have win app that uses menu and toolbar. I set that toolbar property Wrappable=false. But I couldn't find the property for menu. So when resizing a form, menu items could be wrapped to...
3
by: Reb | last post by:
Hi, I am using drop down menu in my pages. In one of my page,there is a listbox control below the menu. This listbox control is hiding the drop down menu items. How can i make the drop down...
3
by: Fred W. | last post by:
(using VS2005) I want to hide a menu item, but setting the Visible property to False does not work! If it's initialy false and I set it to true, that works. Any suggestions? - Fred
2
by: Matt | last post by:
Is there a way to make menu controls behaviours like browser menu like. (file,Edit,View etc) or any other software menu dropdown.. I could do that with inbuild (<items<asp:menu:itemand make the...
2
by: =?Utf-8?B?SmFu?= | last post by:
Hi, I would like to have a View menu like the one in VS(2005), where I can have "two-key" shortcuts (e.g. Ctrl+W followed by E or Ctrl+E). Any suggestions how to do that? Thanks, Jan
1
by: =?Utf-8?B?anAybXNmdA==?= | last post by:
I've got one Context Menu named mi_EasterEggs with three (3) menu items: * mi_FontArial * mi_FontCourier * mi_RawData All menu items have their Visible properties set to False when the form...
0
by: gank456 | last post by:
how to make a new context menu to appear when a tree node is clicked? i've included onmouseclick event handler..but it doesn't work.. where should the handler be placed? is there any way to do...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.